package pl.hotdev.spring.test01;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import pl.hotdev.spring.test01.entities.User;

@Component
public class SampleService {

	@Autowired
	private SessionFactory sesionFactory;

	@Transactional
	public void buisnessLogic1() {
		Session session = sesionFactory.getCurrentSession();
		User user = new User();
		user.setLogin("login");
		user.setName("name");

		session.persist(user);
		System.out.println("Session dirty: " + session.isDirty());

		System.out.println("Registered users: "
				+ session.createQuery("Select count(user) From User user")
						.uniqueResult());

	}

}
